{include file="index/_meta" /}
    <title>店铺信息</title>
<style>
    .dataDiv{
        padding: 16px 0;
        background: #fff;
    }
    .dataDiv p{
        text-align: center;
        margin: 0;
        color: #8F95A0;
    }
    .dataDiv p b{
        font-size: 1.5rem;
    }
    .dataDiv .van-hairline--right::after {
        top: -30%;
        bottom: -30%;
        border: 0 solid #9A9A9A;
        border-right-width: 2px;
    }
</style>
</head>
<body>
<div id="app">
    <van-nav-bar
            title="店铺信息"
            left-text="我的"
            left-arrow
            @click-left="jumpUser"
    ></van-nav-bar>

    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">

        <van-cell-group>
            <van-cell style="padding: 0;">
                <template #title>
                    <van-image :src="info.img_thumb"
                               width="100%"
                               height="200"
                    ></van-image>
                    <van-uploader class="animate-bounce-up"
                                  style="position: absolute;left:50%;top:50%;transform: translate(-50%, -50%);opacity: .5;"
                                  :deletable="no"
                                  :after-read="afterRead"
                    >
                        <van-icon name="upgrade" size="2rem" color="#fff"/>
                    </van-uploader>

                </template>
            </van-cell>
        </van-cell-group>

        <div class="dataDiv">
            <van-row>
                <van-col span="12" class="van-hairline--right" @click="jumpOrder">
                    <p><b style="color: #35C0FE;">{{info.order_num}}</b>&nbsp;个</p>
                    <p>店铺订单</p>
                </van-col>
                <van-col span="12" @click="jumpLog">
                    <p><b style="color: #F75C5F;">{{info.money}}</b>&nbsp;元</p>
                    <p>店铺余额</p>
                </van-col>
            </van-row>
        </div>

        <van-cell-group style="margin: 10px; border-radius: 15px;padding: 10px;overflow: hidden;">
            <van-cell is-link @click="jumpInfo" value="修改资料" >
                <template #title>
                    {{info.name}}
                </template>
            </van-cell>
            <van-cell is-link @click="jumpInfo" value="修改资料" >
                <template #title>
                    {{info.phone}}
                </template>
            </van-cell>
        </van-cell-group>

        <van-cell-group style="margin: 10px; border-radius: 15px;padding: 0 10px;overflow: hidden;">
            <van-cell is-link @click="jumpCash" value="申请提现" >
                <template #title>
                    <van-icon name="gold-coin" color="red" size="1rem"></van-icon>
                    <span style="font-size: 1.5rem;">{{info.money}}</span>
                </template>
            </van-cell>
        </van-cell-group>

    </van-pull-refresh>

    {include file="store/_tabbar" /}
</div>
<script>
    new Vue({
        el: "#app",
        data(){return{
            active:3,
            isLoading:false,
            infoPop:false,
            no:false,
            info:[]
        }},
        created(){
            this.getDetail()
        },
        methods:{
            onRefresh(){
                this.getDetail()
            },
            afterRead(fileObj) {
                // 创建form对象
                let file = fileObj.file
                let that = this
                let formdata1 = new FormData();
                formdata1.append('file', file, file.name);
                //设置请求头
                let config = {
                    headers:{
                        'Content-Type':'multipart/form-data'
                    }
                };
                //this.axios 是因为在main.js写在vue实例里
                const axiosAjax = axios.create({
                    timeout: 1000 * 60, //时间
                    withCredentials: true //跨域携带cookie
                });
                axiosAjax.post("{:url('common/base/uploadFile')}",formdata1,config).then((ret)=>{   //这里的url为后端接口
                    let res = ret.data
                    console.log(res)
                    if(res.code == 0){
                        axios.post("{:url('store/shopEdit')}",{
                            img_thumb:res.data.src,
                            id:that.info.id
                        }).then(function (res2) {
                            let ret = res2.data
                            if (ret.code == 0){
                                that.getDetail()
                            }else{
                                vant.Notify({type:'danger',message:ret.msg})
                            }
                        })
                    }else{
                        vant.Notify({type:'danger',message:res.msg})
                    }
                })
            },
            // 获取商品详情
            getDetail: function () {
                let that = this
                let user = JSON.parse(localStorage.getItem('user'));
                axios.post("{:url('store/getShopDetail')}", {
                    shop_id: "{$Think.session.wechat.shop_id}"
                }).then(function (res) {
                    let ret = res.data
                    that.info = ret.data
                    that.goods = ret.data.goods
                    that.carouselList = ret.data.carouselList

                    that.isLoading = false
                }).catch(function () {
                    vant.Dialog.alert({
                        message: '当前店铺不存在或已下架，请点击返回首页重新选择店铺',
                        confirmButtonText: "返回首页"
                    }).then(() => {
                        // on close
                        window.location.href = "{:url('index/index')}"
                    });
                })
            },
            onTabbarChange(index){
                let url = '';
                switch (index) {
                    case 0:url = "{:url('store/index')}";break;
                    case 1:url = "{:url('store/goods_index')}";break;
                    case 2:url = "{:url('store/order_index')}";break;
                    case 3:url = "{:url('store/info_index')}";break;
                }
                window.location.href = url;
            },
            jumpUser(){
                window.location.href = "{:url('user/index')}"
            },
            jumpOrder(){
                window.location.href = "{:url('store/order_index')}"
            },
            jumpLog(){
                window.location.href = "{:url('store/cash_index')}"
            },
            jumpCash(){
                window.location.href = "{:url('store/cash_cash')}"
            },
            jumpInfo(){window.location.href = "{:url('store/info_info')}"},
        },
    })
</script>
</body>
</html>
